﻿using System;
using System.Collections.Generic;
using WeBlog.Attributes;

namespace WeBlog.Models
{    
    public class SiteConfiguration
    {
		public Guid Id
		{
			get
			{
				if (_id.Equals(Guid.Empty))
				{
					_id = Guid.NewGuid();
				}

				return _id;
			}
			set
			{
				if (_id.Equals(Guid.Empty))
				{
					_id = value;
				}
			}
		}

        [WeBlogRequired]
        public string Name { get; set; }
        
        [WeBlogRequired]
        [UrlRegex]
        public string HostHeaderValues { get; set; }
        public string Description { get; set; }
        public bool AllowOpenRegistration { get; set; }
        public int MinPasswordLength { get; set; }        
        public string ContactEmailSubjectPrefix { get; set; }      
        public bool AllowAnonymousRatings { get; set; }
        public bool AllowAnonymousComments { get; set; }
        public bool AreCommentsEnabled { get; set; }
        public bool ModerateComments { get; set; }
        public bool SocialNetworkingSupport { get; set; }
        public bool TrackPostVisits { get; set; }        
        public int PostsPerPage { get; set; }        
        public string MetaKeywords { get; set; }
        public string MetaDescription { get; set; }        
        public string TrackingScript { get; set; }
        public string DateFormat { get; set; }
        public string Theme { get; set; }
        public string FeedFormat { get; set; }
        
        public string ConnectionString { get; set; }
        public string ProviderName { get; set; }

        /* Email Settings */
        public string SmtpServer { get; set; }
        public string SmtpUserName { get; set; }
        public string SmtpPassword { get; set; }
        public int? SmtpPort { get; set; }        
        public string NoReplyEmailAddress { get; set; }
        public bool? SmtpEnableSsl { get; set; }

        public SiteConfiguration()
        {
			_id = Guid.Empty;
			
			//set some defaults
            AllowOpenRegistration = true;
            MinPasswordLength = 6;

            //set the default values
            AllowAnonymousComments = true;
            AllowAnonymousRatings = true;
            AreCommentsEnabled = true;
            ModerateComments = true;
            SocialNetworkingSupport = true;
            TrackPostVisits = true;
            PostsPerPage = 10;
            Theme = "Default";
            FeedFormat = "RSS";
            DateFormat = "MM/dd/yyy";
            NoReplyEmailAddress = "noreply@weblog.com";
        }                 

        public IEnumerable<string> FindHostHeaders()
        {
            return HostHeaderValues.Split(new [] {','}, StringSplitOptions.RemoveEmptyEntries);
        }

		public override bool Equals(object obj)
		{
			if (base.Equals(obj))
			{
				return true;
			}

			if (obj is SiteConfiguration)
			{
				return Id.Equals(((SiteConfiguration)obj).Id);
			}

			return false;
		}

		public override int GetHashCode()
		{
			return Id.GetHashCode();
		}

		private Guid _id;
    }
}
